/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package estg.dae.projecto.bank.model;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 *
 * @author Marco
 */
public class BrokerSettings {

    private static String BROKER_CONF_FILE_URL = "estg/dae/projecto/bank/utils/broker.properties";
    private static BrokerSettings brokerSettings;
    private final String hostName;
    private final String serviceLocation;
    private final int servicePort;
    private final String connectionFactory;
    private final String messageQueue;

    protected BrokerSettings() {
        try {
            InputStream is = this.getClass().getClassLoader().
                    getResourceAsStream(BROKER_CONF_FILE_URL);
            Properties conf = new Properties();
            conf.load(is);

            hostName = conf.getProperty("broker.hostname");
            serviceLocation = conf.getProperty("broker.serviceLocation");
            servicePort = Integer.parseInt(conf.getProperty("broker.port"));
            connectionFactory = conf.getProperty("broker.connectionFactory");
            messageQueue = conf.getProperty("broker.messageQueue");
            is.close();

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static BrokerSettings getInstance() {
        if (brokerSettings == null) {
            brokerSettings = new BrokerSettings();
        }

        return brokerSettings;
    }

    public String getHostName() {
        return hostName;
    }

    public String getServiceLocation() {
        return serviceLocation;
    }

    public int getServicePort() {
        return servicePort;
    }

    public String getConnectionFactory() {
        return connectionFactory;
    }

    public String getMessageQueue() {
        return messageQueue;
    }
    
}
